package com.nhim.cms.util;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.nhim.cms.dao.ContentTypeElementDefinitionDAO;
import com.nhim.cms.domain.ContentTypeElementDefinition;
@Service
public class ContentTypeElementDefinitionManager {
	@Autowired
	private ContentTypeElementDefinitionDAO contentTypeElementDefinitionDAO;

	@PostConstruct
	public void init() throws Exception {
	}

	@PreDestroy
	public void destroy() {
	}

	@Transactional(readOnly = true)
	public ContentTypeElementDefinition findById(Integer id) {

		return contentTypeElementDefinitionDAO.findById(id);

	}

	@Transactional(readOnly = true)
	public List<ContentTypeElementDefinition> findAll() {
		return contentTypeElementDefinitionDAO.findAll();
	}

	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void save(ContentTypeElementDefinition entity) throws Exception {
		contentTypeElementDefinitionDAO.save(entity);
	}

	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public Boolean delete(Integer id) throws Exception {

		ContentTypeElementDefinition contentTypeElementDefinition = contentTypeElementDefinitionDAO.findById(id);

		if (contentTypeElementDefinition != null)
		{
			contentTypeElementDefinitionDAO.delete(contentTypeElementDefinition);
			return true;
		}
		return false;

	}

	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public ContentTypeElementDefinition saveOrUpdate(ContentTypeElementDefinition entity)
			throws Exception {
				return null;

		
	}

	public static ContentTypeElementDefinitionManager getFromApplicationContext(
			ApplicationContext ctx) {
		return (ContentTypeElementDefinitionManager) ctx
				.getBean(ContentTypeElementDefinitionManager.class);
	}

}
